
// components/multi-input/index.js
const computedBehavior = require("miniprogram-computed").behavior
Component({
  behaviors: [computedBehavior],
  /** 
   * 组件的属性列表
   */
  properties: {
    inputValue: {
      type: [String, Number],
      value: '',
      observer: function (val) {
        this.setData({
          content: val
        })
      }
    },
    maxLen: {
      type: [String, Number],
      value: 500
    },
    placeholder: {
      type: String,
      value: '分享新鲜事...'
    },
  },
  computed: {
    ctrNum(data){
      let wordsNum = data.wordsNum || (data.inputValue).length
      return wordsNum + '/' + data.maxLen
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    wordsNum: 0,
    content: '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onInput(e) {
      console.log(23423423,e.detail.value)
      this.triggerEvent('onInput', e.detail.value)
      const wordsNum = (e.detail.value).length;
      const value = e.detail.value;
      this.setData({
        wordsNum: wordsNum,
        content: value,
      })
      if (wordsNum > this.maxLen) {
        wordsNum = maxLen
      };
    },
    onFocus(e) {
      this.setData({
      })
    },
    onFocus(e) {
    },
    onBlur(e) {
      const value = e.detail.value;
      this.triggerEvent('getInput', value)
    },

  }
})